<template>
  <el-button
    @click="back"
    :type="options&&options.type?options.type:''"
    :size="options&&options.size?options.size:'small'"
    :icon="options.icon"
    :plain="options&&options.plain?options.plain:true"
    :round="options&&options.round?options.round:false"
  >
    {{options&&options.name?options.name:'返回上级'}}
  </el-button>
</template>

<script>
  /*
    返回上级
    options: {参数配置,不必填
       name: '',//string类型,按钮名称,默认 '返回上级'
       type: '',//string类型,类型(primary/success/warning/danger/info/text)
       size: '',//string类型,尺寸(medium/small/ mini),默认 small
       icon: '',//string类型,图标,使用阿里巴巴需要加上iconfont
       plain: true,//boolean值,是否朴素按钮,默认 true
       round: false,//boolean值,是否圆角按钮,默认 false
    }
    pages 为返回到上级的页面路由,必填
    storage 返回上级需要清除的缓存,不必填
  */
  export default {
    name: "BackButton",
    props: {
      options: {//按钮配置
        type: Object,
        required: false
      },
      pages: {//上级页面
        type: String,
        required: true
      },
      storage: {//返回上级需要清除的缓存
        type: String,
        required: false
      }
    },
    methods: {
      back() {//关闭页签并返回上级页面
        this.$store.dispatch('delVisitedViews', this.$route).then((obj) => {
          this.$router.push(this.pages);
        })
      },
    }
  }
</script>

<style scoped>

</style>
